import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'flutter_wifi_connector_platform_interface.dart';

/// An implementation of [FlutterWifiConnectorPlatform] that uses method channels.
class MethodChannelFlutterWifiConnector extends FlutterWifiConnectorPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('flutter_wifi_connector');

  @override
  Future<String?> getPlatformVersion() async {
    final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  Future<Map<String, dynamic>> connectToWifi(String ssid, String password) async {
    try {
      final result = await methodChannel.invokeMethod(
        'connectToWifi',
        {'ssid': ssid, 'password': password},
      );
      return Map<String, dynamic>.from(result as Map);
    } catch (e) {
      return {
        'success': false,
        'message': 'Error: ${e.toString()}',
      };
    }
  }
}
